<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="{{__PUBLIC__}}/assets/ace/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="{{__PUBLIC__}}/assets/ace/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300"/>
    <link rel="stylesheet" href="{{__PUBLIC__}}/assets/ace/css/ace.min.css"/>
    <link rel="stylesheet" href="{{__PUBLIC__}}/assets/ace/css/ace-rtl.min.css"/>
</head>

<body class="login-layout">
<div class="main-container">
    <div class="main-content">
        <div class="row">
            <div class="col-sm-10 col-sm-offset-1">
                <div class="login-container">
                    <div class="center">
                        <h1>
                            <i class="icon-leaf green"></i>
                            <span class="red">jet</span>
                            <span class="white">STAR</span>
                        </h1>
                        <h4 class="blue">&copy; jetstar 为您服务~</h4>
                    </div>

                    <div class="space-6"></div>

                    <div class="position-relative">
                        <div id="login-box" class="login-box visible widget-box no-border">
                            <div class="widget-body">
                                <div class="widget-main">
                                    <h4 class="header blue lighter bigger">
                                        <i class="icon-coffee green"></i>
                                        请输入验证信息
                                    </h4>

                                    <div class="space-6"></div>

                                    <form action="" method="post" id="lg-form">
                                        <fieldset>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="text" class="form-control"
                                                                   placeholder="Username" name="user"/>
															<i class="icon-user"></i>
														</span>
                                            </label>

                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="password" class="form-control"
                                                                   placeholder="Password" name="pswd"/>
															<i class="icon-lock"></i>
														</span>
                                            </label>

                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="text" class="form-control" placeholder="验证码"
                                                                   name="validate"/>

														</span>
                                                <span>
                                                    <img title="点击刷新" src="/index/code_generate" align="absbottom"
                                                         onclick="this.src='/index/code_generate?'+Math.random();">
                                                </span>

                                            </label>

                                            <div class="space"></div>

                                            <div class="clearfix">
                                                <label class="inline">
                                                    <input type="checkbox" class="ace"/>
                                                    <span class="lbl"> 记住我</span>
                                                </label>

                                                <input type="hidden" name="action" value="do_login"/>
                                                <input type="hidden" name="backurl" value="/admin/">
                                                <button type="button"
                                                        class="width-35 pull-right btn btn-sm btn-primary btn-login">
                                                    <i class="icon-key"></i>
                                                    登录
                                                </button>
                                            </div>

                                            <div class="space-4"></div>
                                        </fieldset>
                                    </form>


                                    <div class="social-or-login center">
                                        <span class="bigger-110">或者使用第三方登录</span>
                                    </div>

                                    <div class="social-login center">
                                        <a class="btn btn-primary">
                                            <i class="icon-facebook"></i>
                                        </a>

                                        <a class="btn btn-info">
                                            <i class="icon-twitter"></i>
                                        </a>

                                        <a class="btn btn-danger">
                                            <i class="icon-google-plus"></i>
                                        </a>
                                    </div>
                                </div>
                                <!-- /widget-main -->

                                <div class="toolbar clearfix">
                                    <div>
                                        <a href="#" onclick="show_box('forgot-box'); return false;"
                                           class="forgot-password-link">
                                            <i class="icon-arrow-left"></i>
                                            忘记密码？
                                        </a>
                                    </div>

                                    <div>
                                        <a href="#" onclick="show_box('signup-box'); return false;"
                                           class="user-signup-link">
                                            我要注册
                                            <i class="icon-arrow-right"></i>
                                        </a>
                                    </div>
                                </div>
                            </div>
                            <!-- /widget-body -->
                        </div>
                        <!-- /login-box -->

                        <div id="forgot-box" class="forgot-box widget-box no-border">
                            <div class="widget-body">
                                <div class="widget-main">
                                    <h4 class="header red lighter bigger">
                                        <i class="icon-key"></i>
                                        忘记密码
                                    </h4>

                                    <div class="space-6"></div>
                                    <p>
                                        请输入你的注册邮箱接收我们发送的操作说明
                                    </p>

                                    <form>
                                        <fieldset>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="email" class="form-control"
                                                                   placeholder="Email"/>
															<i class="icon-envelope"></i>
														</span>
                                            </label>

                                            <div class="clearfix">
                                                <button type="button" class="width-35 pull-right btn btn-sm btn-danger">
                                                    <i class="icon-lightbulb"></i>
                                                    好了，发送!
                                                </button>
                                            </div>
                                        </fieldset>
                                    </form>
                                </div>
                                <!-- /widget-main -->

                                <div class="toolbar center">
                                    <a href="#" onclick="show_box('login-box'); return false;"
                                       class="back-to-login-link">
                                        返回登录
                                        <i class="icon-arrow-right"></i>
                                    </a>
                                </div>
                            </div>
                            <!-- /widget-body -->
                        </div>
                        <!-- /forgot-box -->

                        <div id="signup-box" class="signup-box widget-box no-border">
                            <div class="widget-body">
                                <div class="widget-main">
                                    <h4 class="header green lighter bigger">
                                        <i class="icon-group blue"></i>
                                        注册jetstar
                                    </h4>

                                    <div class="space-6"></div>
                                    <p> 请输入以下内容: </p>

                                    <form action="" method="" id="frm-register">
                                        <fieldset>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="email" class="form-control" placeholder="邮箱"  name="r_mail" id="mail" required/>
															<i class="icon-envelope"></i>
														</span>
                                            </label>

                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="text" class="form-control" placeholder="帐号"  name="r_user" required/>
															<i class="icon-user"></i>
														</span>
                                            </label>

                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="password" class="form-control" placeholder="密码"  name="r_password" id="password" required/>
															<i class="icon-lock"></i>
														</span>
                                            </label>

                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="password" class="form-control" placeholder="确认密码" name="r_password" id="ps2" required/>
															<i class="icon-retweet"></i>
														</span>
                                            </label>

                                            <label class="block">
                                                <input type="checkbox" class="ace"/>
                                                <input type="hidden" name="action" value="do_register"/>
														<span class="lbl"> 我接受 <a href="#">jetstar用户协议</a> </span>
                                            </label>

                                            <div class="space-24"></div>

                                            <div class="clearfix">
                                                <button type="reset" class="width-30 pull-left btn btn-sm">
                                                    <i class="icon-refresh"></i>
                                                    重置
                                                </button>

                                                <button type="button" class="width-65 pull-right btn btn-sm btn-success btn-register">  ok,注册
                                                    <i class="icon-arrow-right icon-on-right"></i>
                                                </button>
                                            </div>
                                        </fieldset>
                                    </form>
                                </div>

                                <div class="toolbar center">
                                    <a href="#" onclick="show_box('login-box'); return false;"
                                       class="back-to-login-link">
                                        <i class="icon-arrow-left"></i>
                                        返回登录
                                    </a>
                                </div>
                            </div>
                            <!-- /widget-body -->
                        </div>
                        <!-- /signup-box -->
                    </div>
                    <!-- /position-relative -->
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </div>
</div>


<script src="{{__PUBLIC__}}/static/js/jquery.js"></script>
<script src="{{__PUBLIC__}}/static/js/jquery.validate.min.js"></script>


<script type="text/javascript">
    function show_box(id) {
        jQuery('.widget-box.visible').removeClass('visible');
        jQuery('#' + id).addClass('visible');
    }
</script>

<script>

    $(function () {
        jQuery.extend(jQuery.validator.messages, {
            required: "必选字段",
            remote: "请修正该字段",
            email: "请输入正确格式的电子邮件",
            url: "请输入合法的网址",
            date: "请输入合法的日期",
            dateISO: "请输入合法的日期 (ISO).",
            number: "请输入合法的数字",
            digits: "只能输入整数",
            creditcard: "请输入合法的信用卡号",
            equalTo: "请再次输入相同的值",
            accept: "请输入拥有合法后缀名的字符串",
            maxlength: jQuery.validator.format("请输入一个 长度最多是 {0} 的字符串"),
            minlength: jQuery.validator.format("请输入一个 长度最少是 {0} 的字符串"),
            rangelength: jQuery.validator.format("请输入 一个长度介于 {0} 和 {1} 之间的字符串"),
            range: jQuery.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
            max: jQuery.validator.format("请输入一个最大为{0} 的值"),
            min: jQuery.validator.format("请输入一个最小为{0} 的值")
        });


        $("#frm-register").validate({
            rules: {
                mail: {
                    required: "请输入Email地址",
                    email: true,
                    minlength: 4
                },
                password: {
                    required: true,
                    minlength: 4
                }
            },

            confirm_password: {
                required: true,
                minlength: 4,
                equalTo: "#password"
            }
        });
        //登录
        $(".btn-login").click(function () {
            $.ajax({
                type: 'post',
                url: "/account/login",
                data: {
                    user: $("input[name='user']").val(),
                    pswd: $("input[name='pswd']").val(),
                    action: 'do_login',
                    validate: $("input[name='validate']").val()
                },
                success: function (data, status) {
                    data = $.parseJSON(data);
                    if (data.status == 1) {               //登录成功
                        window.location.href = "/admin/";

                    } else {
                        alert(data.msg);
                    }
                },
                error: function () {

                    alert("发送请求失败！");
                }

            });
        });

        //注册
        $(".btn-register").click(function(){

            if($("#password").val() != $("#ps2").val()){
                alert('两次输入的密码不一致');
                return;
            }

            $.ajax({
                type    : 'post',
                url     : '/account/register',
                data    :{
                    mail    : $("input[name='r_mail']").val(),
                    user    : $("input[name='r_user']").val(),
                    pswd    : $("input[name='r_password']").val(),
                    action  : 'do_register'
                },
                success     : function(data,status){
                    data = $.parseJSON(data);
                    if(data.has){
                        alert('注册成功,请到你的邮箱查看验证邮件');
                    }else{
                        alert(data.msg);
                    }
                },
                error       :function(){
                    alert('出现错误!');
                }

            })
        })
    })
</script>

</body>
</html>
